import createProps from '../../js/createProps.js'
import { dispatchEvent } from '../../js/events.js'
import { setCss, makeId } from '../../js/utils.js'
import {EVENT_COLLAPSE_TOGGLE, TIME_MEDIUM} from '../../js/constants.js'
import breakpoint from '../../js/breakpoints.js'
class Collapse extends HTMLElement {
constructor() {
super()
this.classList.add('u-collapse')
this.classList.add('animate-click')
// Init properties
this.label = ''
this.heading = 0
this.iconLeft = ''
this.iconRight = '24/ui/chevron-bottom'
this.collapsible = 'right' // null / left / right / both
this.expanded = false
this.collapseId = ''
this.textClass = 'h-md-regular'
this.async = false
this.onlyMobile = false
// Events
this.boundOnClick = this.onClick.bind(this)
this.boundOnResize = this.onResize.bind(this)
}
connectedCallback() {
createProps(this, true)
this.isHeading = this.heading >=1 && this.heading <= 6
if (this.onlyMobile && !breakpoint.is.mobile) {
this.renderNoCollapse()
}
else {
this.setId()
this.render()
this.setMaxHeight()
this.bindEvent()
if (this.async) {
this.observeSlot()
}
}
}
renderNoCollapse() {
this.innerHTML = `
${this.isHeading
? `
${this.label}
` } ${this.slot} ` } setId() { if (this.collapseId === '') { this.collapseId = makeId(5) } } render() { this.innerHTML = ` ${this.renderTitle()} ${this.renderPanel()} ` this.button = this.querySelector('button[aria-controls]') this.panel = this.querySelector('div[role="region"]') } renderTitle() { return ` ` } renderIcon(icon, position) { if (icon === '') { return '' } if (this.collapsible === 'both' || this.collapsible === position) { return `